//    Copyright 2021 Cardinal
//
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//
//        http://www.apache.org/licenses/LICENSE-2.0
//
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.

@FunctionalInterface
interface Shape {
    double area(double num);
}

interface CalArea{
    double getArea();
    double getArea(Shape s);
}

class Square implements Shape,CalArea {
    Square(double a) {
        this.a = a;
    }

    @Override
    public double area(double num) {
        return num * num;
    }
    @Override
    public double getArea() {
        return area(a);
    }
    @Override
    public double getArea(Shape s) {
        return s.area(a);
    }

    private double a;
}

class Circle implements Shape,CalArea {
    Circle(double r) {
        this.r = r;
    }

    @Override
    public double area(double num) {
        return Math.PI * num * num;
    }
    @Override
    public double getArea() {
        return area(r);
    }
    @Override
    public double getArea(Shape s) {
        return s.area(r);
    }

    private double r;
}

public class homework_2 {
    static <T extends CalArea> void showArea(T s){
        System.out.println("area:" + s.getArea());
    }

    static <T extends CalArea> void showArea(T s,Shape lambdaS) {
        System.out.println("area:" + s.getArea(lambdaS));
    }
    public static void main(String[] args) {
        Square s = new Square(20);
        Circle c = new Circle (20);
        showArea(s);
        showArea(c);
        System.out.println("----上面是直接算的，下面是Lambda算的----");
        showArea(s,a->a*a);
        showArea(c, r->Math.PI * r * r);
    }
}
